package com.tronsis.library.util;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

/**
 * @author scofield@tronsis.com
 * @date 2018/9/20 17:55
 */
public class EditTextUtil {
    public static void setTextChangedButtonBg(final List<TextView> list, final Button button) {
        TextWatcher textWatcher = new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                for (TextView editText : list) {
                    if (TextUtils.isEmpty(editText.getText().toString())) {
                        button.setEnabled(false);
                        return;
                    }
                }
                button.setEnabled(true);
            }
        };

        for (TextView editText : list) {
            editText.addTextChangedListener(textWatcher);
        }

    }
}
